<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">    </div>
    <template id="my-app">
        <h2>今天温度：{{temp}}度</h2>
        <h3>建议穿：{{suggestion}}</h3>

        <button @click="add">+</button>
        <button @click="dec">-</button>
    </template>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
        const App = {
            template:'#my-app',
            data() {
                return {
                    temp:10,
                }
            },
            computed: {
                suggestion() {//计算属性，响应式执行，当它依赖的数据源发生变更时，会自动重新执行
                    let res = '夹克'

                    if(this.temp >= 20){
                        res = '短袖'
                    }else if(this.temp <= 0){
                        res = '羽绒服'
                    }else{
                        res = '夹克'
                    }
                    return res
                }
            },
            methods: {
               add() {
                this.temp+=5

                // if(this.temp >= 20){
                //     this.suggestion = '短袖'
                // }else if(this.temp <= 0){
                //     this.suggestion = '羽绒服'
                // }else{
                //     this.suggestion = '夹克'
                // }
               },
               dec() {
                this.temp-=5
                // if(this.temp >= 20){
                //     this.suggestion = '短袖'
                // }else if(this.temp <= 0){
                //     this.suggestion = '羽绒服'
                // }else{
                //     this.suggestion = '夹克'
                // }
               }
            }
        }

        Vue.createApp(App).mount('#app')
    </script>
</body>
</html>